package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.mapper.AuditFlowMapper;
import com.zygh.policeasset.mapper.CompleteMapper;
import com.zygh.policeasset.mapper.UploadFileMapper;
import com.zygh.policeasset.pojo.Completed;
import com.zygh.policeasset.pojo.Project;
import com.zygh.policeasset.pojo.ProjectNameType;
import com.zygh.policeasset.pojo.Section;
import com.zygh.policeasset.pojo.TableType;
import com.zygh.policeasset.pojo.UploadFile;
import com.zygh.policeasset.utils.AuditUtil;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/CompletedSerivce.class */
public class CompletedSerivce {
    @Autowired
    private CompleteMapper completeMapper;
    @Autowired
    UploadFileMapper uploadFileMapper;
    @Autowired
    AuditFlowMapper auditFlowMapper;
    @Autowired
    AuditFlowService auditFlowService;

    public List<Project> getProject(Integer userId) {
        return this.completeMapper.getProject(userId);
    }

    public List<ProjectNameType> selectBytype() {
        return this.completeMapper.selectBytype();
    }

    public List<ProjectNameType> findSectionByType(String projectNo) {
        return this.completeMapper.findSectionByType(projectNo);
    }

    public List<Section> getAdd(String projectNo, Integer userId) {
        return this.completeMapper.getAdd(projectNo, userId);
    }

    public Integer findCount() {
        return this.completeMapper.findCount();
    }

    public int add(Completed completed) {
        String now = DateUtil.now();
        String flowNo = AuditUtil.getFlowNo(now);
        completed.setFlowNo(flowNo);
        int completedId = 0;
        try {
            this.auditFlowService.add(completed.getUserId(), flowNo, now, TableType.COMPLETED.getName(), TableType.COMPLETED.getType(), completed.getProjectNo(), completed.getSectionId());
            this.completeMapper.add(completed);
            completedId = completed.getId().intValue();
            List<UploadFile> uploadFileList = completed.getUploadFileList();
            for (int i = 0; i < uploadFileList.size(); i++) {
                uploadFileList.get(i).setProjectId(completedId);
                uploadFileList.get(i).setProjectName("completed");
                uploadFileList.get(i).setCreateDate(DateUtil.now());
                this.uploadFileMapper.add(uploadFileList.get(i));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return completedId;
    }

    public PageInfo findAll(String name, Integer status, Integer companyId, Integer pageNum,
                            Integer pageSize, String time1, String time2,
                            Integer category, Integer userId) {
        PageHelper.startPage(pageNum.intValue(), pageSize.intValue());
        return new PageInfo<>(this.completeMapper.findAll(name, status, companyId, time1, time2, category, userId));
    }

    public List<Completed> findByProjectNoPage(String no) {
        return this.completeMapper.findByProject(no);
    }

    public PageInfo findByStatus(int status, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.completeMapper.findByStatus(status));
    }

    public int delete(Integer id) {
        int res = 0;
        try {
            res = this.completeMapper.delete(id);
            this.uploadFileMapper.delete(id.intValue(), "completed");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }

    public Completed selectById(Integer id) {
        return this.completeMapper.selectById(id);
    }

    public int update(Completed completed) {
        return this.completeMapper.update(completed);
    }

    public Integer updateStatus(int id, int status) {
        return this.completeMapper.updateStatus(id, status);
    }

    public List<Completed> toExcel(Integer id, String name, String companyId, String time1, String time2) {
        return this.completeMapper.toExcel(id, name, companyId, time1, time2);
    }
}